

#include "mekr.h"
#include <iostream>
// #include "solid.h"
#include "face.h"
#include "loop.h"
// #include "point.h"
// #include "vertex.h"
#include "halfedge.h"
#include "edge.h"


MEKR::MEKR( HalfEdge* _h1, HalfEdge* _h2 )
: he1( _h1 )
, he2( _h2 )
{

}


void
MEKR::execute()
{
  std::cout << "\nMEKR::execute() \n";

//X    Edge            *n_ed;
//X    register HalfEdge    *n_he1, *n_he2;
//X    Face            *f;
//X    Loop            *l1, *l2;
//X    l1 = he1->wloop;
//X    l2 = he2->wloop;
//X    f = l1->lface;
  register HalfEdge *n_he1, *n_he2;
  Loop* l1 = he1->getLoop();
  Loop* l2 = he2->getLoop();
  Face* f = l1->getFace();

  n_he1 = l2->getLedg();
  do
  {
      n_he1->setWloop( l1 );
  }
  while((n_he1 = n_he1->getNxt()) != l2->getLedg());
//X    n_he1 = l2->ledg;
//X    do
//X    {
//X        n_he1->wloop = l1;
//X    }
//X    while((n_he1 = n_he1->nxt) != l2->ledg);

  Edge* n_ed = new Edge( f->getSolid() );
//X    n_ed = (Edge *) new(EDGE, f->fsolid);

  n_he1 = n_ed->addhe( he1->getVtx(), he1, PLUS);
  n_he2 = n_ed->addhe( he2->getVtx(), he2, MINUS);
//X    n_he1 = addhe(n_ed, he1->vtx, he1, PLUS);
//X    n_he2 = addhe(n_ed, he2->vtx, he2, MINUS);

  n_he1->setNxt( he2 );
  n_he2->setNxt( he1 );
  he2->setPrv( n_he1 );
  he1->setPrv( n_he2 );
//X    n_he1->nxt = he2;
//X    n_he2->nxt = he1;
//X    he2->prv = n_he1;
//X    he1->prv = n_he2;

  if(f->getLoopOut() == l2)
    f->setFlout( l1 );
//X    if(f->flout == l2) f->flout = l1;

  delete l2;
//X    del(LOOP, l2, l2->lface);

}


void
MEKR::unExecute()
{
  std::cout << "\nMEKR::unExecute() NOT IMPLEMENTED!\n";
}







